package com.taoes.simpledocker.service.imple;

import com.github.dockerjava.api.DockerClient;
import com.taoes.simpledocker.config.DockerClientFactory;
import com.taoes.simpledocker.service.ContainerService;
import com.taoes.simpledocker.service.DockerTestService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Slf4j
@Service
@RequiredArgsConstructor
public class DockerTestServiceImpl implements DockerTestService {

  private final DockerClientFactory factory;

  @Override
  public Void ping() {
    final DockerClient client = factory.get("DEFAULT2");
    System.out.println("======docker信息如下：");
    System.out.println(client.infoCmd().exec());
    return client.pingCmd().exec();
  }

  @Autowired
  ContainerService containerService;



  public void testRun() {
//    RunNewContainerRequest runNewContainerRequest = new RunNewContainerRequest("redis:latest");
//    HashMap<String, String> bindsMap = new HashMap<String, String>();
//    HashMap<Integer, Integer> portMap = new HashMap<>();
//    portMap.put(6379, 6379);
//    bindsMap.put("/testsimpledocker/redis.conf", "/usr/local/etc/redis/redis.conf");
//    bindsMap.put("/testsimpledocker/data", "/data");
//    runNewContainerRequest.setPro(true)
//            .setBindsMap(bindsMap)
//            .setPortBound(portMap)
//            .setContainerName("redisTest")
//            .setMaximumRetryCount(3)
//            .setNetworkMode("bridge")
//            .setCpuCount(2L)
//            .setMemory(204800000L);
//    containerService.run(runNewContainerRequest);

  }


}
